/* ============================================================
 * Part of 'Autostop' project
 * Under GPL license - http://www.gnu.org/licenses/gpl.html
 * (c) 2006 - Autostop team
 */

///\file camera.h Interface of the camera-interface library.

#ifndef CAMERA_H
#define CAMERA_H

#include <stdint.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

// ========================================================
// Types and constants

// return codes
#define CAMERA_OK			0			///< No error
#define CAMERA_ERROR		1			///< Unrecoverable error
#define CAMERA_SMALLBUFFER	2			///< Supplied buffer is too small
#define CAMERA_EOF			3			///< No more data

// data types
#define sequence_t			void*		///< Image sequence handler
#define SEQUENCE_INVALID	0			///< Invalid sequence

// ========================================================
// Functions

/// Initisalizes camera
///\return ok or error code
int camera_init(void);

/// Returns image width [pixels]
int camera_image_width(void);

/// Returns image height [pixels]
int camera_image_height(void);

/// Gets image data from camera
/// If buffer is too small, CAMERA_SMALLBUFFER is returned.
///\par	pbuffer (OUT)		- user-supplied buffer for image data. must be big enough
///\par	bufsize				- size of the buffer
///\par	ptimestamp (OUT)	- buffer for image timestamp
///\return return code as defined in camera.h
int camera_get_image( uint8_t* pbuffer, size_t bufsize, uint64_t* ptimestamp );

/// Requests jpeg2k sequence from camera
///\return sequence handle to be used in subsequent operations, or IVALID_SEQENCE
///\todo propably some params will be needed
sequence_t camera_open_sequence(void);

/// Gets image from open sequence. If function succeeds, image is removed from sequnce.
/// When there is no more images, CAMERA_EOF is returned.
/// If buffer is too small, CAMERA_SMALLBUFFER is returned, image is not removed form sequence.
///\par	sequence			- sequence handler
///\par pbuffer (OUT)		- user-supplied buffer for image data. must be big enough
///\par	bufsize				- size of the buffer
///\return return code as defined in camera.h
int camera_read_sequence( sequence_t sequence, uint8_t* pbuffer, size_t bufsize );

/// Closes sequence, releases all resources
///\par sequence 	- sequence to be closed
void camera_close_sequence( sequence_t sequence );

/// Returns pointer to  internal buffer containing last error descritpion
///\return pointer to global buffer. Do not free!
const char* camera_error_message();

#ifdef __cplusplus
} // extern "C"
#endif /* __cplusplus */

#endif /*CAMERA_H*/

// eof

